/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package game.chips;

import game.Player;
import java.util.concurrent.atomic.AtomicIntegerArray;


public abstract class Chip implements Runnable {
    private Player owner;

    private AtomicIntegerArray cur_state = new AtomicIntegerArray(2);
    private AtomicIntegerArray before_turn = new AtomicIntegerArray(2);
    private AtomicIntegerArray after_turn = new AtomicIntegerArray(2);

    private volatile boolean may_turn;
    private volatile boolean out;
    private volatile boolean first;

    Chip(Player owner) {
        this.owner = owner;
    }

    public void setState(AtomicIntegerArray indXY) {
        cur_state = indXY;
    }

    public AtomicIntegerArray getState() {
        return cur_state;
    }

    abstract void turn();

    @Override
    abstract public String toString();

    
    public void setAfterTurn(AtomicIntegerArray new_coord) { 
        after_turn = new_coord;
    }
    public void setBeforeTurn() {
        before_turn = cur_state;
    }
    
    public AtomicIntegerArray getAfterTurn() { 
        return after_turn;
    }
    public AtomicIntegerArray getBeforeTurn() { 
        return before_turn;
    }

    public void setTurn() {
        may_turn = !may_turn;
    }

    public boolean getTurn() {
        return may_turn;
    }

    public void setOut() {
        out = true;
    }

    public boolean getOut() {
        return out;
    }

    public boolean wasMoved() {
        return !before_turn.equals(after_turn);
    }

    public String stepToString() {
        String res = " " + before_turn.get(0) + "-" + before_turn.get(1) + " to " + after_turn.get(0) + "-" + after_turn.get(1);
        return res;
    }

    public boolean isFirst() {
        return first;
    }

    public void setFirst() {
        first = true;
    }
}
